package com.chinaisafe.user.vo.request;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.chinaisafe.base.common.vo.request.PageReqVo;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.validated.UpdateGroup;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import com.chinaisafe.user.entity.SysTenant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * SysTenantReqVO
 * Description：租户请求值对象
 *
 * @author xuefu.shu
 * @date  2024-07-12 10:22:08
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "SysTenantReqVO", description = "租户请求值对象")
public class SysTenantReqVO extends PageReqVo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键id")
    @NotNull(groups = UpdateGroup.class, message = "主键id不能为空" )
    private Long id;

    @Schema(description = "乐观锁版本")
    private Integer version;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "租户编码")
    private String code;

    @Schema(description = "简称")
    private String alias;

    @Schema(description = "统一信用代码")
    private String creditCode;

    @Schema(description = "上级租户")
    private Long parentId;

    @Schema(description = "租户类型")
    private String type;

    @Schema(description = "系统运行日")
    private LocalDate useStartDate;

    @Schema(description = "租期")
    private LocalDate tenancyDate;

    @Schema(description = "是否启用")
    private Boolean enable;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "管理员id")
    private Long managerUserId;


    @Override
    public List getOrderItem() {
        List<OrderItem> orderItems = new ArrayList<>();
        OrderItem orderItem = new OrderItem();
        orderItem.setColumn("id");
        orderItem.setAsc(true);
        orderItems.add(orderItem);

        return orderItems;
    }

    /**
     * 将请求值对象装换为实体
     * @return SysTenant
     * @author xuefu.shu
     * @date 2024-07-12 10:22:08
     */
    public SysTenant convertToEntity() {
        SysTenant entity = new SysTenant();
        entity.setId(this.id);
        entity.setVersion(this.version);
        // 给实体对应的字段赋值 可根据实际业务删减
        entity.setName(this.name);
        entity.setCode(this.code);
        entity.setAlias(this.alias);
        entity.setCreditCode(this.creditCode);
        entity.setParentId(this.parentId);
        entity.setType(this.type);
        entity.setUseStartDate(this.useStartDate);
        entity.setTenancyDate(this.tenancyDate);
        entity.setEnable(this.enable);
        entity.setRemark(this.remark);
        entity.setManagerUserId(this.managerUserId);
        return entity;
    }

}
